<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class branch_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();
		$data=array();

	} 	
		
	public function create_user_type($insert)
	{
		$this->db->insert('user_type',$insert);
	}
	
	public function create_department($insert)
	{
		$this->db->insert('department',$insert);
	}
	
	public function insert($data){
		
	$this->db->insert('branch',$data);
			
}
		
	public function get_branch(){
		
		$query = $this->db->get('branch');

		return $query;
	}	

public function edit_branch($id){
		$query = $this->db->get_where('branch', array('id' => $id));
		return $query;
	}

public function update($edit_id, $data){
		$this->db->update('branch',$data,array('id'=>$edit_id));
	}

public function delete($id){
		$this->db->delete('branch',array('id'=>$id));		
	}
	

function get()
	{
		
	   $this->datatables
			->select("id,name,code,phone_no,address")
			->from("branch")
			/*->join('warehouses_products', 'products.id = warehouses_products.product_id')
			->select('(SELECT SUM(warehouses_products.quantity) FROM warehouses_products WHERE warehouses_products.product_id=products.id) AS totalQuantity', FALSE)
			
			->select("warehouses_products.product_id as productid, products.image as image, products.code, products.name, products.unit, products.cost, products.price, alert_quantity,  sum(warehouses_products.quantity) as 'totalQuantity'")
			->from('warehouses_products')
			->join('products', 'warehouses_products.product_id=products.id', 'inner')
			->group_by("products.id")*/
			->add_column("Actions", 
			"<center>			<a href='edit_branch/$1'>
								<i class='icon-edit'></i>
								</a>
							    <a href='delete_branch/$1' onClick=\"return confirm('".'Do u want to Delete The Branch!'."')\">
								<i class='icon-trash'></i>
								</a></center>", "id")
			->unset_column('id');
		
		
	   return  $this->datatables->generate();
	}


	
	
	


}
